package com.ruoyi.patrol.service.impl;

import java.util.List;

import com.google.gson.Gson;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.patrol.utils.AIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.patrol.mapper.PtPoliceRecordMapper;
import com.ruoyi.patrol.domain.PtPoliceRecord;
import com.ruoyi.patrol.service.IPtPoliceRecordService;

/**
 * 报警记录Service业务层处理
 *
 * @author lkm
 * @date 2024-10-30
 */
@Service
public class PtPoliceRecordServiceImpl implements IPtPoliceRecordService
{
    @Autowired
    private PtPoliceRecordMapper ptPoliceRecordMapper;

    /**
     * 查询报警记录
     *
     * @param id 报警记录ID
     * @return 报警记录
     */
    @Override
    public PtPoliceRecord selectPtPoliceRecordById(Long id)
    {
        return ptPoliceRecordMapper.selectPtPoliceRecordById(id);
    }

    /**
     * 查询报警记录列表
     *
     * @param ptPoliceRecord 报警记录
     * @return 报警记录
     */
    @Override
    public List<PtPoliceRecord> selectPtPoliceRecordList(PtPoliceRecord ptPoliceRecord)
    {
        return ptPoliceRecordMapper.selectPtPoliceRecordList(ptPoliceRecord);
    }

    /**
     * 新增报警记录
     *
     * @param ptPoliceRecord 报警记录
     * @return 结果
     */
    @Override
    public int insertPtPoliceRecord(PtPoliceRecord ptPoliceRecord)
    {
        ptPoliceRecord.setCreateTime(DateUtils.getNowDate());
        Gson request = AIUtils.request(ptPoliceRecord.getAudioUrl());
        ptPoliceRecord.setReturn(request);
        return ptPoliceRecordMapper.insertPtPoliceRecord(ptPoliceRecord);
    }

    /**
     * 修改报警记录
     *
     * @param ptPoliceRecord 报警记录
     * @return 结果
     */
    @Override
    public int updatePtPoliceRecord(PtPoliceRecord ptPoliceRecord)
    {
        ptPoliceRecord.setUpdateTime(DateUtils.getNowDate());
        return ptPoliceRecordMapper.updatePtPoliceRecord(ptPoliceRecord);
    }

    /**
     * 批量删除报警记录
     *
     * @param ids 需要删除的报警记录ID
     * @return 结果
     */
    @Override
    public int deletePtPoliceRecordByIds(Long[] ids)
    {
        return ptPoliceRecordMapper.deletePtPoliceRecordByIds(ids);
    }

    /**
     * 删除单条报警记录
     *
     * @param id 报警记录ID
     * @return 结果
     */
    @Override
    public int deletePtPoliceRecordById(Long id)
    {
        return ptPoliceRecordMapper.deletePtPoliceRecordById(id);
    }

    /**
     * 根据任务id查询报警记录
     * @param taskId 报警器推送过来的报警记录id
     * @return 返回一条报警记录
     */
    @Override
    public PtPoliceRecord selectPtPoliceRecordByTaskid(String taskId) {
        return ptPoliceRecordMapper.selectPtPoliceRecordByTaskid(taskId);
    }
}
